package com.ddd.mill.infrastructure.persistent.repository.impl.attribute;

import com.ddd.mill.domain.aggregate.attribute.entity.Attribute;
import com.ddd.mill.domain.aggregate.attribute.repository.AttributeRepository;
import com.ddd.mill.infrastructure.persistent.dao.attribute.AttributeDao;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author liu
 * @title: AttributeMyBatisRepositoryImpl
 * @projectName trading-center
 * @date 2020/11/3010:28
 */
@Component
public class AttributeMyBatisRepositoryImpl implements AttributeRepository {
    @Resource
    AttributeDao dao;
    @Override
    public Attribute load(Long id) {
        return dao.selectById(id);
    }

    @Override
    public Long save(Attribute entity) {
        if (!Objects.isNull(entity.getId()) && !Objects.isNull(dao.selectById(entity.getId()))) {
            dao.updateById(entity);
        } else {
            dao.insert(entity);
        }
        return entity.getId();
    }

}
